package org.huel.backend.service.impl;

import org.huel.backend.domain.dto.CourseAttendanceDTO;
import org.huel.backend.domain.dto.DashboardSummaryDTO;
import org.huel.backend.domain.entity.AttendanceSummary;
import org.huel.backend.domain.entity.CourseAttendance;
import org.huel.backend.mapper.AttendanceSummaryMapper;
import org.huel.backend.mapper.CourseAttendanceMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.stream.Collectors;

@Service
public class DashboardService {

    @Autowired
    private AttendanceSummaryMapper attendanceSummaryMapper;

    @Autowired
    private CourseAttendanceMapper courseAttendanceMapper;

    /**
     * 获取最新的出勤汇总数据
     * @return 出勤汇总数据
     */
    public AttendanceSummary getAttendanceSummary() {
        return attendanceSummaryMapper.selectLatestSummary();
    }

    /**
     * 获取所有课程的出勤情况
     * @return 课程出勤列表
     */
    public List<CourseAttendance> getAllCourseAttendance() {
        return courseAttendanceMapper.selectAllCourseAttendance();
    }

    /**
     * 获取出勤人数最高的前N门课程
     * @param limit 数量限制
     * @return 课程列表
     */
    public List<CourseAttendance> getTopPresentCourses(int limit) {
        return courseAttendanceMapper.selectTopPresentCourses(limit);
    }

    /**
     * 获取缺勤人数最高的前N门课程
     * @param limit 数量限制
     * @return 课程列表
     */
    public List<CourseAttendance> getTopAbsentCourses(int limit) {
        return courseAttendanceMapper.selectTopAbsentCourses(limit);
    }
}